package cd.safe.school.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;
import cd.safe.school.R;
import cd.safe.school.adapter.SchoolSMSAdapter2;
import cd.safe.school.bean.SharePager;
import cd.safe.school.util.NetWorkUtil;
import cd.safe.school.util.Parse;

public class SchoolSMS extends Activity {
	private ListView personlist;
	private List<Map<String, Object>> lists = new ArrayList<Map<String, Object>>();
	private Handler handler = new Handler();
	private List<SharePager> lst;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.school_sms);
		personlist = (ListView) findViewById(R.id.school_sms);
		new Thread(new Runnable() {

			@Override
			public void run() {
				lst = Parse.parsepage(0, 1, 7);
				for (SharePager sp : lst) {
					Map<String, Object> map = new HashMap<String, Object>();
					map.put("person_biaoti", "ischecked" + sp.getIschecked());
//					String time = String.valueOf(sp.getSendTime());
//					map.put("sendtime", NetWorkUtil.today(time));
//					map.put("person_xinxiji", "msg:" + sp.getMsg());
					lists.add(map);

				}
				final SchoolSMSAdapter2 adapter = new SchoolSMSAdapter2(
						SchoolSMS.this, lists);
				handler.post(new Runnable() {

					@Override
					public void run() {
						personlist.setAdapter(adapter);

					}
				});

			}
		}).start();

		personlist.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Toast.makeText(SchoolSMS.this, lst.get(position).toString(),
						Toast.LENGTH_LONG).show();
				Intent intent = new Intent(SchoolSMS.this,
						SchoolSMS_detail.class);
				startActivity(intent);

			}
		});

	}
}
